<template>
	<view class="content b-t">
		<view class="point-history">
			<view class="list b-b" v-for="(item, index) in pointList" :key="index" 
			:style="index == pointList.length - 1?'':'border-bottom: 1rpx solid #E5E5E5;'"
				@click="toOrderDetail(item.orderId)"
			>
				<view class="left">
					<view class="tran-type">
						{{item.sourceTyoe == '0'?'购物':'管理员修改'}}({{item.sourceTyoe == '0'?item.orderId:''}})
					</view>
					<view class="tran-time">
						{{item.createTime}}
					</view>
				</view>
				<view class="right">
					<view class="point-minus">
						{{item.changeCount > 0?'+ ' + item.changeCount: item.changeCount}}						
					</view>
					<!-- <view class="balance">
						剩余积分:{{myChangeCount}}
					</view> -->
				</view>
			</view>
		</view>
		

	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import empty from "@/components/empty";
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		components: {
			uniLoadMore,
			empty
		},
		data() {
			return {
				source: 0,
				pointList: [],
				pageNo: 1,
				pageSize: 20,
				loadingType:'',
				myChangeCount: 0
			}
		},
		onLoad(option) {
			this.myChangeCount = uni.getStorageSync('userInfo').integration
			this.searchUserPointStatement();
		},
		onReachBottom() {
			// this.loadMore();
		},
		//下拉刷新
		onPullDownRefresh() {
			//重新加载数据
			// this.resetPage();
			// this.searchUserPointStatement();
		},
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		methods: {
			//加载更多
			loadMore() {
				if (this.loadingType === 'more') {
					this.pageNo = this.pageNo + 1;
					this.searchUserPointStatement();
				}
			},
			resetPage() {
				this.pageNo = 1;
				this.pointList = [];
			},
			navTo(url) {
				uni.navigateTo({
					url: url
				})
			},
			//添加或修改成功之后回调
			refreshList() {
				this.resetPage();
				this.searchUserPointStatement();
			},
			//查询用户奖金明细
			searchUserPointStatement() {
				let that = this;
				this.$api.request.pointStatementList({
					memberId: uni.getStorageSync('userInfo').id
				}, res => {
					console.log(res);
					if(res.code == 200){
						this.pointList = res.data
					}
				})
			},
			// 跳转到订单详情
			toOrderDetail(orderId) {
				const that = this
				this.$api.request.getOrderInfoType({
					memberId: uni.getStorageSync('userInfo').id,
					orderId: orderId,
				}, res => {
					console.log(res);
					if (res.code == 200) {
						// 如果该订单是商品
						if (res.data == 1) {
							uni.navigateTo({
								url: '/pagesA/sys/user/orderDetail?id=' + orderId 
							});
						}
						// 如果该订单是服务
						else if (res.data == 2) {
							that.$api.request.orderByInfoData({
								wxId: uni.getStorageSync('userInfo').id,
								orderId: orderId,
							}, response => {
								if(response.code == 200){
									let status = response.data[0].subscribeState == '0'?'1':(response.data[0].subscribeState == '1'?'3':(response.data[0].subscribeState == '2'?'4':'5'))
									uni.navigateTo({
										url: '/pagesA/appointment/service/index?status=' + status,
										success(resp) {
											resp.eventChannel.emit('item', response.data[0])
										}
									})
								}
							})
						}
					}
				})
			
			},
		}
	}
</script>

<style lang='scss'>
	page {
		padding-bottom: 120upx;
		background: #f8f8f8;
	}

	.content {
		position: relative;
	}

	.list {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 20upx 30upx;
		;
		background: #fff;
		position: relative;
		.amount{
			color: $base-color
		}
		.apply{
			color: #fff;
			border-radius: 10px;
			background: linear-gradient(left, #f5cb54, #9e760d);
			width: 80px;
			height: 30px;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 28upx;
		}
	}

	.left {
		text-align: left;
		.tran-type {
			font-size: $font-base;
			color: $font-color-dark;
		}
		
		.tran-time{
			font-size: $font-base;
			color: $font-color-light;
			padding-top:20upx;
		}
	}
	.right {
		text-align: right;
		.point-plus {
			font-size: $font-lg;
			color: #D47169;
		}
		.point-minus {
			font-size: $font-lg;
			color: green
		}
		.balance{
			font-size: $font-base;
			color: $font-color-light;
			padding-top:20upx;
		}
	}
	

	.icon-bianji {
		display: flex;
		align-items: center;
		height: 80upx;
		font-size: 40upx;
		color: $font-color-light;
		padding-left: 30upx;
	}
	.point-history{
		margin-top: 10upx;
	}
	
	.gray-border{
		width: auto;
		height: 1rpx;
		background: #FFFFFF;
	}
</style>
